import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  ParseIntPipe,
  Post,
  Put,
  UseGuards,
} from '@nestjs/common';
import {
  ApiBearerAuth,
  ApiOperation,
  ApiParam,
  ApiQuery,
  ApiTags,
} from '@nestjs/swagger';
import { JwtAuthGuard } from '@/auth/guard/jwt-auth.guard';
import { Roles, RolesGuard } from '@/auth/guard/roles.guard';
import { PaymentService } from './payment.service';
import { CreatePaymentDto } from '@/modules/payment/dto/create-payment.dto';
import { UpdatePaymentDto } from '@/modules/payment/dto/update-payment.dto';

@ApiBearerAuth()
@ApiTags('支付模块')
@Controller('payments')
@UseGuards(JwtAuthGuard, RolesGuard)
export class PaymentController {
  private readonly paymentService: PaymentService;

  constructor(paymentService: PaymentService) {
    this.paymentService = paymentService;
  }

  @ApiOperation({ summary: '查询所有支付记录' })
  @Roles('admin')
  @Get()
  findAll() {
    return this.paymentService.findAll();
  }

  @ApiOperation({ summary: '查询指定支付记录' })
  @ApiParam({ name: 'id', description: '支付记录ID' })
  @Get('payment-detail/:id')
  findOne(@Param('id', ParseIntPipe) id: number) {
    return this.paymentService.findOne(id);
  }

  @ApiOperation({ summary: '查询指定订单的支付记录' })
  @ApiQuery({ name: 'orderId', description: '订单ID' })
  @Get('order/:orderId')
  findByOrderId(@Param('orderId', ParseIntPipe) orderId: number) {
    return this.paymentService.findByOrderId(orderId);
  }

  @ApiOperation({ summary: '创建支付记录' })
  @Post()
  create(@Body() createPaymentDto: CreatePaymentDto) {
    return this.paymentService.create(createPaymentDto);
  }

  @ApiOperation({ summary: '更新支付记录' })
  @ApiParam({ name: 'id', description: '支付记录ID' })
  @Put(':id')
  update(
    @Param('id', ParseIntPipe) id: number,
    @Body() updatePaymentDto: UpdatePaymentDto,
  ) {
    return this.paymentService.update(id, updatePaymentDto);
  }

  @ApiOperation({ summary: '删除支付记录' })
  @ApiParam({ name: 'id', description: '支付记录ID' })
  @Delete(':id')
  delete(@Param('id', ParseIntPipe) id: number) {
    return this.paymentService.delete(id);
  }
}
